transfer signup_data from registrationtbl to userstbl - php

Good day does anyone can help me about my problem?
i have a signup_form all the data inputted will insert to my registrationtbl, my problem is the code below just delete the data from registrationtbl. how can i move the data to the userstbl and remove it from the registrationtbl? thank you . hope someone may help me..
the code is also came from one of the topics here..
<?php
$con=mysqli_connect("localhost","root","","scouts");
if ( isset($_GET['id']) ) {`enter code here`
$id = $_GET['id'];
$result = mysqli_query($con,"SELECT * FROM registration WHERE id='$id'");
while($row = mysqli_fetch_array($result))
{
echo $row['idno'] . " " . $row['surname'];
echo "<br>";
}
$row = mysqli_query($con,"INSERT INTO users (surname, firstname, middlename, gender, idno, password, signup_date) 'SELECT * from registration WHERE id =$id");
$sql = mysqli_query($con,"DELETE FROM registration WHERE id='$id'");
echo "its deleted";
}
?>

why are you using 2 tables:
simply use users table only, and add a status field to the table, when user registered the status may be 0, when registration approved change status to 1... so there is no need for 2 tables...
or if u have to use both tables, my suggession is the use of a database trigger to insert value to the second table from 1st.

Related

is it possible to send a query in database if the no. of likes are above 50

I am creating a page in which user can upload their picture and other users can like it.
Now is there any method that when the user's like goes above 50 lets say 51, then execute a query that saves this users name and postid. And then show a notification to user that your post have crossed 50 likes.
Also i dont want the query to execute again and again i want it to send that query only once for that particular post i am using php any suggestions
this is the code that i used but didnt work:
<?php if ($vote>=50){
mysqli_query($con, "insert into notifications (user_id,post_id) values('$id3','$pixid')")or die(mysqli_error($con));
}
?>
try below :
if($vote > 50) {
$result = mysqli_query("select * from notifications where user_id = " . $id3 . " And post_id = " . $pixid);
if(!mysqli_num_rows($result)) {
mysqli_query($con, "insert into notifications (user_id,post_id) values('$id3','$pixid')")or die(mysqli_error($con));
}
}

Why I have empty record in MySQL?

In our system they asked us to add research interest but when we add new user, we should assign an interest to him/her. It's adding successfully to the database table, we have problem which is we get zero record in the interest_id database table, why?
Here all research interest added successfully to database:
As you see in picture below when admin add a new user he chooses multiple interests and assign them to a user:
Here is screenshot of user profile as you can see interests that admin assigned to new user:
The problem is that it don't write interest id to database?
Below you can see the codes and SQL table:
<p>
<label>Research Areas</label>
<select name="interest_id[]" class="small-input" multiple>
<?php
$query = "SELECT * FROM research_interest ORDER BY name ASC";
$result = mysqli_query($link, $query);
while($row = mysqli_fetch_object($result))
{
?>
<option value="<?php echo $row->id; ?>"><?php echo $row->name; ?></option>
<?php
}
?>
</select>
</p>
Here is also codes for MySQL:
if(isset($_POST['action'])) {
switch($_POST['action']) {
case 'user_add':
$user_id = mysqli_real_escape_string($link,$_POST['user_id']);
$email = mysqli_real_escape_string($link,$_POST['email']);
$password = rand_pass(8);
$title_id = intval($_POST['title_id']);
$user_type_id = intval($_POST['usertype_id']);
$department_id = intval($_POST['department_id']);
$view_publication = mysqli_real_escape_string($link,$_POST['publication']);
$referee = mysqli_real_escape_string($link,$_POST['referee']);
$gender = mysqli_real_escape_string($link,$_POST['gender']);
$creation_date = date('Y.m.d');
//Interest
if(!empty($_POST['interest_id']) && is_array($_POST['interest_id'])) {
foreach ($_POST['interest_id'] as $interest)
{
$query = "INSERT INTO user_interest (user_id, interest_id)
VALUES ('$user_id', '$interest')";
$result = mysqli_query($link,$query);
}
}
//SQL Query
$query = "INSERT INTO user (user_id, email, title, user_type_id, department_id, referee, gender, password, view_publication, creation_date)
VALUES ('$user_id', '$email', '$title_id', '$user_type_id', '$department_id', '$referee', '$gender', '$password', '$view_publication', '$creation_date')";
$result = mysqli_query($link,$query);
echo '<script type="text/javascript">';
echo 'window.location = "mail.php?action=user_mail&user_id='.$user_id.'"';
echo '</script>';
break;
}
}
And this is a user_interest table shows that these three research IDs assign to user 1
but here it show that interest_id is zero , it don't shows ids of research interest that added to user 1
You are not including interest_id in your Insert query to the users table. So the table is assigning a default value of 0.
You're not inserting anything into the "interest_id" column in the second query so it's defaulting to zero. It looks like you're trying to set up a many to many relationship (one user can have many interests and one interest can belong to many users). In that case you'll need to set up a junction table (http://en.wikipedia.org/wiki/Junction_table) to handle the relationship.

Using MYSQL to call a row from a table

I am trying to show specific information for my logged in users, i can call the user_name, but i have been able also to call info from the "website" entry which holds the html for the page, i need to be able to call "website" to each logged in user, i.e Susan (user_name) has the html showing when she logs in, BUT Barry (user_name) has the same html showing as susan, as it is being called from Susans row! Please help it is driving me mad!
Here is the code that is on the myaccount.php:
Welcome To <?php echo $_SESSION['user_name'];?>'s Account Page</strong>
<?php
if (isset($_GET['msg'])) {
echo "<div class=\"error\">$_GET[msg]</div>";
}
?>
<?php
$data = mysql_query("SELECT * FROM users") or die(mysql_error());
$info = mysql_fetch_array( $data );
Print "<b></b> ".$info['$website'] . " ";
?>
You have to add a WHERE clause to your query. If you have a field in your table called user_name it will be like this :
"SELECT * FROM users WHERE user_name = '" . $_SESSION['user_name'] . "'";
Note : You are using a deprecated (mysql_query) you should use rather (mysqli_query) which has different syntax
http://php.net/manual/en/mysqli.query.php
Have you tried
$data = mysql_query("SELECT * FROM users WHERE username='$_SESSION[user_name]'") or die(mysql_error());

Displaying the users information from the database

I am trying to created a way to call information from the database for a user to view. Such as they log in and it has their registered information viewed. I have this
session_start();
if($_SESSION['id'])
$result = mysql_query("SELECT * FROM User WHERE `id` = $_SESSION[id]")
or die(mysql_error());
while($row = mysql_fetch_array( $result )) {
echo '<b>First Name:</b>' .$row['fname'];
echo '<br>';
echo '<b>Last Name:</b>' .$row['lname'];
}
but nothing shows up. My database name is megan, table is user, fields i want displayed are first name (fname) and last name (lname).
Can someone point me in the right direction. Thank you in advance!
Bad array indexing.
$result = mysql_query("SELECT * FROM User WHERE `id` = " . $_SESSION['id'])
You should turn on PHP error displaying.
First change this,
if(isset($_SESSION['id']))
because you have to check if the session isset correctly then do the query,
then the sql change to this,
$result = mysql_query("SELECT * FROM User WHERE `id` = ".$_SESSION['id'])

mySQL database: printing specific row or rows from a db table

please assist. i have a database with a couple of tables and rows and i want the php to print specific rows as and when i want it to. at the moment it renders all the content of the spesific table on my webpage. in future, i would like it to display the contents of a specific table if a cirtain user is logged in so im going to do that when i understand if statements and get over this hurdle 1st. my code is as follows:
<?php
include 'connect-mysql.php';
echo "<br/>";
$query = "SELECT CUSTOMER_NAME, RAMSCODE FROM customer";
$result = mysql_query($query) or die (mysql_error());
while($row = mysql_fetch_array($result))
{
echo "{$row['CUSTOMER_NAME']} <br>" .
"RAMSCODE: {$row['RAMSCODE']} <br>" ;
}
?>
To fetch specific rows from a table you have to include a WHERE clause in your SQL statement.
For example:
$query = "SELECT CUSTOMER_NAME, RAMSCODE FROM customer WHERE customer_id = 2";
Match the WHERE xxxxx clause to any column in your table
You need to specifiy yor criteria as a where clause in the SQL
$query = "SELECT CUSTOMER_NAME, RAMSCODE FROM customer where RAMSCODE = %1";
$result = mysql_query($query,mysql_real_escape_string($yourcode)) or die (mysql_error());
Also you really need to Read the Manuals!
As far as i've get what you want is to display only that row from customers table, which customer is logged in. you can use some thing like this:
while($row = mysql_fetch_array($result))
{
if($row['CUSTOMER_NAME'] == " //Customer Logged In (customer name from session)"){
echo "{$row['CUSTOMER_NAME']} <br>" .
"RAMSCODE: {$row['RAMSCODE']} <br>" ;
}else{
//do nothing or continue with printing all
}
}
Hope this helps.

Categories