Go Back   Web User Forums > All Other Technical Help Topics > Web design & build

Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old 12-08-18, 20:13
TheClash TheClash is offline
Enthusiastic contributor
 
Join Date: Sep 2015
Posts: 260
Default sql or sqli

test page yyyyyz
Fatal error: Uncaught Error: Call to undefined function mysql_connect() in /homepages/34/d747981205/htdocs/SQL/insert.php:30 Stack trace: #0 {main} thrown in /homepages/34/d747981205/htdocs/SQL/insert.php on line 30

$mysql_host="db749575322.db.1and1.com";
$mysql_user="dbo749575";
$mysql_password="99";
$my_database = "db749575";
$table_name = "wp_jmpp_options";

/*Please Do not change anything below this line */

$link = mysql_connect("$mysql_host", "$mysql_user", "$mysql_password", "$my_database")
or die("Could not connect : " . mysql_error($link));
echo "Connected successfully";
mysql_select_db($link, "$my_database") or die("Could not select database");

echo '<p>Connection to MySQL server successfully established.</p >';











$sql="INSERT INTO Persons (firstname, lastname)

VALUES

('$_POST[fname]','$_POST[lname]')";



if (!mysql_query($sql,$con))

{

die('Error: ' . mysql_error());

}

echo "1 record added";



mysql_close($con)

?>


1111
</body>

</html>


I dont understand this error should i be using mysql or my sqli?
Reply With Quote
  #2  
Old 12-08-18, 21:28
Sneakybeaky's Avatar
Sneakybeaky Sneakybeaky is offline
Passionate member
 
Join Date: Aug 2012
Location: Gosport Hants
Posts: 1,311
Default Re: sql or sqli

Quote:
I dont understand this error should i be using mysql or my sqli?
You should use mysqli
MySQL extension is deprecated and will not be available in future PHP versions. It is recommended to use the MySQLi extension with PHP 5.5 and above.
__________________
Contrariwise,continued Tweedledee, if it was so, it might be; and if it were so, it would be: but as it isn't, it ain't. That's logic.
Reply With Quote
  #3  
Old 13-08-18, 16:36
TheClash TheClash is offline
Enthusiastic contributor
 
Join Date: Sep 2015
Posts: 260
Default Re: sql or sqli

Fatal error: Uncaught Error: Call to undefined function mysql_connect() in /homepages/34/d747981205/htdocs/SQL/testdb.php:10 Stack trace: #0 {main} thrown in /homepages/34/d747981205/htdocs/SQL/testdb.php on line 10

using code given by 1 & 1 i get error.

echo "testing";

$connect = mysql_connect($host_name, $user_name, $password, $database);
if (mysql_errno()) {
die('<p>Failed to connect to MySQL: '.mysql_error().'</p>');
} else {
echo '<p>Connection to MySQL server successfully established.</p >';
}
?>


what do they mean undefined function it is part of php??
Reply With Quote
  #4  
Old 13-08-18, 17:12
Sneakybeaky's Avatar
Sneakybeaky Sneakybeaky is offline
Passionate member
 
Join Date: Aug 2012
Location: Gosport Hants
Posts: 1,311
Default Re: sql or sqli

Which version of php?
mysql_* functions were deprecated in PHP 5.5.0 and were removed in PHP 7.

Have you tried:
mysqli_connect($host_name, $user_name, $password, $database)

http://php.net/manual/en/book.mysqli.php
__________________
Contrariwise,continued Tweedledee, if it was so, it might be; and if it were so, it would be: but as it isn't, it ain't. That's logic.
Reply With Quote
  #5  
Old 13-08-18, 20:16
TheClash TheClash is offline
Enthusiastic contributor
 
Join Date: Sep 2015
Posts: 260
Question Re: sql or sqli

<?php

/* Connecting, selecting database */
/* Please change the values below to connect to the users database...*/

$mysqli_host="db749575m";
$mysqli_user="dbo7492";
$mysqli_password="saco99";
$my_database = "db72";
$table_name = "nametable";

echo "adder22";

/*Please Do not change anything below this line */

$link = mysqli_connect("$mysqli_host", "$mysqli_user", "$mysqli_password", "$my_database")
or die("Could not connect : " . mysqli_error($link));
echo "Connected successfully";
mysqli_select_db($link, "$my_database") or die("Could not select database");



the code above is workign and connecting to the database.


code below original was in sql format and not sure how to upgrade it?






$sqli="INSERT INTO nametable (firstname, lastname)

VALUES

('$_POST[fname]','$_POST[lname]')";



if (!mysqli_query($sqli,$con))

{

die('Error: ' . mysqli_error()); <<<< only getting this far recordiing error on screen>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>

}

echo "1 record added";



mysqli_close($con)

?>


not sure how to fix this as hosts now wont let yuo send in support tickets.
Reply With Quote
  #6  
Old 13-08-18, 20:46
Sneakybeaky's Avatar
Sneakybeaky Sneakybeaky is offline
Passionate member
 
Join Date: Aug 2012
Location: Gosport Hants
Posts: 1,311
Default Re: sql or sqli

It should take this form
$sqli="INSERT INTO name (fname, lname)
VALUES
( '$_POST[fname]', '$_POST[lname]', )";

change names to suit.
__________________
Contrariwise,continued Tweedledee, if it was so, it might be; and if it were so, it would be: but as it isn't, it ain't. That's logic.
Reply With Quote
  #7  
Old 14-08-18, 19:25
TheClash TheClash is offline
Enthusiastic contributor
 
Join Date: Sep 2015
Posts: 260
Question Re: sql or sqli

<h1>A small example page to insert some data in to the MySQL database using PHP</h1>

<form action="insert.php" method="post">

Firstname: <input type="text" name="fname" /><br><br>

Lastname: <input type="text" name="lname" /><br><br>



<input type="submit" />

</form>

</body>
</html>


the above is html page that calls the post to php insert.php


echo "adder22";

/*Please Do not change anything below this line */

$link = mysqli_connect("$mysqli_host", "$mysqli_user", "$mysqli_password", "$my_database")
or die("Could not connect : " . mysqli_error($link));
echo "Connected successfully";
mysqli_select_db($link, "$my_database") or die("Could not select database");



$fname=$_POST['Firstname'];
$lname=$_POST['Lastname'];

$query = "INSERT INTO nametable('','$fname','$lname')";
$mysqli->query($query); [ line 33]
$mysqli->close();


Fatal error: Uncaught Error: Call to a member function query() on null in /homepages/34/d747981205/htdocs/SQL/insert.php:33 Stack trace: #0 {main} thrown in /homepages/34/d747981205/htdocs/SQL/insert.php on line 33

nametable


columns
new
fistname
lastname
name
user_id



above is my database in php myadmin


have i made an error in runnign table in php myadmin or is error in my php code?
Reply With Quote
  #8  
Old 14-08-18, 19:40
TheClash TheClash is offline
Enthusiastic contributor
 
Join Date: Sep 2015
Posts: 260
Exclamation Re: sql or sqli

$sqli="INSERT INTO nametable (fname, lname)
VALUES
( '$_POST[fname]', '$_POST[lname]', )";

echo "1 record added";

?>


I changed names in php admin to lname fname



script sayign 1 record addign yet database appears NULL


How do yuo view full database in phpadmin?
Reply With Quote
  #9  
Old 14-08-18, 21:18
Sneakybeaky's Avatar
Sneakybeaky Sneakybeaky is offline
Passionate member
 
Join Date: Aug 2012
Location: Gosport Hants
Posts: 1,311
Default Re: sql or sqli

Quote:
script sayign 1 record addign yet database appears NULL
Then there is an error in your code. Msql tries to be clever and assumes it knows what the user wants. Check variable names, table names, syntax.
I notice you have listed ‘fistname’


Quote:
Originally Posted by TheClash View Post

How do yuo view full database in phpadmin?
There are lenty of tutorials out there:

https://www.youtube.com/watch?v=Ecy2abJnDH4
__________________
Contrariwise,continued Tweedledee, if it was so, it might be; and if it were so, it would be: but as it isn't, it ain't. That's logic.
Reply With Quote
  #10  
Old 15-08-18, 20:01
TheClash TheClash is offline
Enthusiastic contributor
 
Join Date: Sep 2015
Posts: 260
Default Re: sql or sqli

i changed these to fname and lname but my code says database connected , records added but when i go to php my admin - no record has been added. yet database on php admin will add a record so is working.


output the database2bConnected successfully
Fatal error: Uncaught Error: Call to undefined function mysql_query() in /homepages/34/d747981205/htdocs/SQL/output.php:27 Stack trace: #0 {main} thrown in /homepages/34/d747981205/htdocs/SQL/output.php on line 27

echo"output the database2b";

/*Please Do not change anything below this line */

$link = mysqli_connect("$mysqli_host", "$mysqli_user", "$mysqli_password", "$my_database")
or die("Could not connect : " . mysqli_error($link));
echo "Connected successfully";
mysqli_select_db($link, "$my_database") or die("Could not select database");

---lower part of code --

$query="SELECT * FROM nametable";
$result=mysql_query($query);

$num=mysql_numrows($result);

mysql_close();

echo "<b><center>Database Output</center></b><br><br>";

$i=0;
while ($i < $num) {

$firstname=mysql_result($result,$i,"fname");
$lastname=mysql_result($result,$i,"lname");


echo "<b>$firstname $lastname</b><br>";

$i++;
}

?>


sometimes the code seems to be sqli and other sql

is this what is causing error.???


this is the html input screen

<h1>A small example page to insert some data in to the MySQL database using PHP</h1>

<form onSubmit="insert.php" method="post">

Firstname: <input type="text" name="fname" /><br><br>

Lastname: <input type="text" name="lname" /><br><br>




</form>

</body>
</html>


this is the database injection part

echo "adder24zzzyyyyyyyyyyyyyyyyyyyzz23";

/*Please Do not change anything below this line */

$link = mysqli_connect("$mysqli_host", "$mysqli_user", "$mysqli_password", "$my_database")
or die("Could not connect : " . mysqli_error($link));
echo "Connected successfully";
mysqli_select_db($link, "$my_database") or die("Could not select database");





$sqli="INSERT INTO nametable ('fname', 'lname')
VALUES
( '$_POST[fname]', '$_POST[lname]', )";



echo "1 record added"; < gets here but no record added?

?>




Reply With Quote
Reply

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Search the forum

Search

© Dennis Publishing Limited Licensed by Felden





All times are GMT. The time now is 03:16.


Powered by vBulletin® Version 3.8.4
Copyright ©2000 - 2018, Jelsoft Enterprises Ltd.
Copyright Dennis Publishing 2010, All rights reserved