Forum Moderators: coopster

Message Too Old, No Replies

MySQL Update Table 2 issue

         

dmccabe

1:27 pm on Sep 14, 2021 (gmt 0)

Top Contributors Of The Month



Hi Guys,

I am just having trouble trying to insert into table: $result2 = mysqli_query($connection, $query2);

Thank you:)



require('connect.php');
// If the values are posted, insert them into the database.
if (isset($_POST['user']) && isset($_POST['password'])){
$user = $_POST['user'];
$email = $_POST['email'];
$firstname = mysqli_real_escape_string($connection, $_POST['firstname']);
$firstname = mysqli_real_escape_string($connection, $_POST['firstname']);
$password = mysqli_real_escape_string($connection, $_POST['password']);
$t=time();
$query = "INSERT INTO `chat` (user, password, email, time) VALUES ('$user', '$password', '$email', '$t')";
$query2 = "INSERT INTO `profile` (username, email, firstname) VALUES ('$user', '$email', '$firstname')";

$result = mysqli_query($connection, $query);
$result2 = mysqli_query($connection, $query2);

if($result){
$smsg = "User Created Successfully. Feel free to start or enter a chat room <a href='http://example.com/lobby'>Return To Chat Lobby</a>";
}else{
$fmsg ='User Registration Failed Invalid query: ' . mysql_error($connection) . "\n";
}
if($result2){
$smsg = "User Created Successfully. Feel free to start or enter a chat room <a href='http://example.com/lobby'>Return To Chat Lobby</a>";
}else{
$fmsg ='User Registration Failed Invalid query: ' . mysql_error($connection) . "\n";
}
}





ERROR:


Fatal error: Uncaught Error: Call to undefined function mysql_error() in /var/www/html/signup/signup2.php:29 Stack trace: #0 {main} thrown in /var/www/html/signup/signup2.php on line 29





[edited by: not2easy at 1:45 pm (utc) on Sep 14, 2021]
[edit reason] please use example.com [/edit]

not2easy

1:52 pm on Sep 14, 2021 (gmt 0)

WebmasterWorld Administrator 10+ Year Member Top Contributors Of The Month



Hi dmccabe and welcome to WebmasterWorld [webmasterworld.com]

I can suggest you read the code at line 29 of the "signup2.php" file to see the error message which might be helpful.

I'm sorry I can't be much help with the PHP code, there are many others who may spot the issue and help - but I would personally be wary of using code with passwords and private data on a site using http: protocols today.

dmccabe

2:12 pm on Sep 14, 2021 (gmt 0)

Top Contributors Of The Month



This is a prototype script so just trying to figure out why $query2 = "INSERT INTO `profile` (username, email, firstname) VALUES ('$user', '$email', '$firstname')"; fails.

Thanks

//LINE 29
 }else{
$fmsg ='User Registration Failed Invalid query: ' . mysql_error($connection) . "\n";

robzilla

7:31 pm on Sep 14, 2021 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



You need to use mysqli_error(): [php.net...]

The mysql_error() function (noticed the missing i) belongs to the old MySQL extension that's been deprecated. You're already using MySQLi functions to query the database, so you just need to swap in mysqli_error() for mysql_error() [php.net].

I wouldn't print out any database errors publicly, though. And as not2easy noted, you should be using HTTPS.

phranque

8:39 pm on Sep 14, 2021 (gmt 0)

WebmasterWorld Administrator 10+ Year Member Top Contributors Of The Month



once you fix the undefined function error, you should be able to see the mysql error message.

dmccabe

10:10 pm on Sep 14, 2021 (gmt 0)

Top Contributors Of The Month



Thaks guys that worked by adding the missing i.